package com.hollowlatte.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Hollow Latte
 * @date 2021/4/26 15:24
 */
public class Result {
    private Boolean success;
    private String code;
    private String message;
    private Map<String, Object> data = new HashMap<>();

    /**
     * 防止通过无参构造new该对象
     */
    private Result() {

    }

    public static Result ok() {
        Result result = new Result();
        result.setSuccess(true);
        result.setCode("00000");
        result.setMessage("成功");
        return result;
    }

    public static Result error() {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode("B0001");
        result.setMessage("系统执行出错");
        return result;
    }

    public static Result error(String code, String message) {
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public Result data(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public Result data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
